import javax.microedition.media.Manager;
import javax.microedition.media.MediaException;
import javax.microedition.media.Player;
import javax.microedition.media.PlayerListener;
import javax.microedition.media.control.VolumeControl;

final class cls_o extends cls_s
        implements inf_m {

    cls_o(cls_ab ab) {
        super.a = ab;
        super.b = false;
    }

    public final cls_af a(int i) {
        SoundPlayer c1 = new SoundPlayer(super.a);
        c1.c = 0;
        c1.d = i;
        boolean flag = false;
        cls_af af1 = (c1);
        Player player = (Player) af1.b;
        try {
            c1.b = Manager.createPlayer(getClass().getResourceAsStream("/" + i + ".mid"), "audio/midi");
            player.realize();
            player.prefetch();
        }
        catch (MediaException _ex) {
            d(c1);
        }
        catch (Exception _ex) {
            flag = true;
        }
        if (flag)
            try {
                c1.b = Manager.createPlayer(getClass().getResourceAsStream("/" + i + ".amr"), "audio/amr");
                player.realize();
                player.prefetch();
            }
            catch (Exception _ex) {
                d(c1);
                c1 = null;
            }
        try {
            ((VolumeControl) player.getControl("VolumeControl")).setLevel(100);
        }
        // Misplaced declaration of an exception variable
        catch (Exception ex) {
            System.out.println("Volume Control threw: " + ex.toString());
        }
        return c1;
    }

    public final boolean a(cls_af af1, boolean flag) {
        try {
            Player player = (Player) af1.b;
            if (af1.c != 0)
                player.stop();
            af1.a = flag;
            player.setLoopCount(flag ? -1 : 1);
            af1.c = 2;
            player.start();
            return true;
        } catch (Exception ex) {
            System.out.println("Sound Exception: " + ex.toString());
            return false;
        }
    }

    public final void a(cls_af af1) {
        try {
            Player player = (Player) af1.b;
            player.stop();
            af1.c = 0;
            player.setMediaTime(0L);
            Thread.sleep(20L);
        }
        catch (Exception eaf1) {
            System.out.println(eaf1.toString());
        }
    }

    public final void b(cls_af af1) {
        try {
            Player player = (Player) af1.b;
            player.stop();
            af1.c = af1.a ? 1 : 0;
            player.setMediaTime(0L);
            Thread.sleep(20L);
            return;
        }
        catch (Exception eaf1) {
            System.out.println(eaf1.toString());
        }
    }

    public final void c(cls_af af1) {
        try {
            Player player = (Player) af1.b;
            player.start();
            af1.c = 2;
            return;
        }
        catch (Exception eaf1) {
            System.out.println("Resume failed: " + eaf1.toString());
        }
    }

    public final void d(cls_af af1) {
        try {
            Player player = (Player) af1.b;
            if (af1.c != 0)
                player.stop();
            player.close();
            return;
        }
        catch (Exception eaf1) {
            System.out.println(eaf1.toString());
        }
    }

    public final void a(cls_af af1, cls_af af2) {
        e(af1);
        ((Player) af2.b).addPlayerListener((PlayerListener) af2);
    }

    public final void e(cls_af af1) {
        if (af1 != null)
            ((Player) af1.b).removePlayerListener((PlayerListener) af1);
    }

    final void a(Object obj, int i) {
        try {
            ((VolumeControl) ((Player) obj).getControl("VolumeControl")).setLevel(100);
        }
        catch (Exception ex) {
            System.out.println("Volume Control threw: " + ex.toString());
        }
    }
}